/*
 * Copyright (c) 2021.
 * @User: XiaoZhenRS
 * @QQ: 1419158026
 * @Gitee: gitee.com/XiaoZhengRS
 * @GitHub: github.com/XiaoZhengRS
 */

package com.xiaozhengkeji.blogsuper.oauth;

import cn.dev33.satoken.stp.StpInterface;
import com.alibaba.fastjson.JSON;

import com.xiaozhengkeji.blogsuper.base.service.UserEntityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class StpInterfaceImpl implements StpInterface {

    @Autowired
    UserEntityService userEntityService;

    /**
     * 返回一个账号所拥有的权限码集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginKey) {
        return JSON.parseArray(userEntityService.selectByPrimaryKey(Integer.parseInt(loginId.toString())).getPermission(), String.class);
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginKey) {
        return JSON.parseArray(userEntityService.selectByPrimaryKey(Integer.parseInt(loginId.toString())).getPermission(), String.class);
    }
}
